<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
		
        <div class="container mt-1">
          <el-form inline size="small">
			<div class="flex items-center search_form">
				<div>
					合作商id：
					<el-input
					v-model="searchForm.user_id"
					placeholder="请输入用户id"
					style="width: 200px; margin-right: 10px;"
					size="small"
					></el-input>
				</div>
                <!-- <div>
					业务员id：
					<el-input
					v-model="searchForm.s_user_id"
					placeholder="请输入用户id"
					style="width: 200px; margin-right: 10px;"
					size="small"
					></el-input>
				</div> -->
				<div>
					类型：
					<el-select
					v-model="searchForm.type"
					placeholder="请选择"
					style="width: 200px; margin-right: 10px;"
					size="small"
					>
                     <el-option label="不限" value="-1"></el-option>
					  <el-option label="奖励" value="1"></el-option>
					  <el-option label="提现" value="2"></el-option>
					</el-select>
				</div>
                <div>
					二维码编号：
					<el-input
					v-model="searchForm.qr_sn"
					placeholder="请输入二维码编号"
					style="width: 200px; margin-right: 10px;"
					size="small"
					></el-input>
				</div>
				<div>
					状态：
					<el-select
					v-model="searchForm.status"
					placeholder="请选择"
					style="width: 200px; margin-right: 10px;"
					size="small"
					>
                     <el-option label="不限" value="-1"></el-option>
					  <el-option label="已核销" value="1"></el-option>
					  <el-option label="未核销" value="0"></el-option>
					</el-select>
				</div>
				
				 <div style="margin-left: 10px;">
					<el-button type="primary" size="mini" @click="mySearch">搜索</el-button>
					<el-button size="mini" @click="reset">重置</el-button>
					<!-- <el-button type="primary" size="mini" @click="addBtn">添加</el-button> -->
				 </div>
			</div>
			
           
			
           
          </el-form>
        </div>
      </div>
      <el-table
        :data="list"
        style="width: 100%"
        size="mini"
        height="600px"
        :highlight-current-row="true"
        :header-cell-style=" {fontWeight:'bold'}"
      >
        <el-table-column
          prop="id"
          label="ID"
          min-width="50"
        />
        <el-table-column label="合作商姓名"
	  					align="center"
                         prop="nick_name"
                         min-width="100"
                         :show-overflow-tooltip="true">
		
        </el-table-column>
        <el-table-column label="合作商id"
	  					align="center"
                         prop="user_id"
                         min-width="100"
                         :show-overflow-tooltip="true">
        </el-table-column>
		<el-table-column label="奖励/提现金额"
		                 prop="reward_price"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
		</el-table-column>

        <!-- <el-table-column label="核销业务员id"
		                 prop="s_user_id"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <div>
                        {{ scope.row.s_user_id ? scope.row.s_nick_name : '--' }}
                    </div>
                </template>
		</el-table-column>
        <el-table-column label="核销业务员姓名"
		                 prop="s_nick_name"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true" >
            <template slot-scope="scope">
                <div>
                    {{ scope.row.s_nick_name ? scope.row.s_nick_name : '--' }}
                </div>
            </template>
        </el-table-column> -->
        <el-table-column label="二维码编号"
		                 prop="qr_sn"
						 align="center"
		                 min-width="200"
		                 :show-overflow-tooltip="true">
		</el-table-column>
        <el-table-column label="类型"
		                 prop="uid"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
            <template slot-scope="scope">
                <el-tag v-if="scope.row.type==1" type="info" effect="dark" size="small">奖励</el-tag>
                <el-tag v-if="scope.row.type==2" type="danger" effect="dark" size="small">提现</el-tag>
            </template>
        </el-table-column>
        <!-- <el-table-column label="核销时间"
		                 prop="uid"
						 align="center"
		                 min-width="150"
		                 :show-overflow-tooltip="true">
            <template slot-scope="scope">
                <div>
                    {{ scope.row.hx_time ? scope.row.hx_time : '--' }}
                </div>
            </template>
        </el-table-column> -->
        <el-table-column label="状态"
		                 prop="status"
						 align="center"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
            <template slot-scope="scope">
                <div v-if="scope.row.type==2">
                    <!-- <el-tag v-if="scope.row.status==0" type="info" effect="dark" size="small">未核销</el-tag>
			        <el-tag v-if="scope.row.status==1" type="danger" effect="dark" size="small">已核销</el-tag> -->
					<!-- 换成开关按钮只显示一个文字 -->
					<el-switch
					v-model="scope.row.status"
					active-value="1"
					inactive-value="0"
					@change="handleChange(scope.row)"
					>
						
					</el-switch>
					<span>{{ scope.row.status==1 ? '已打款' : '未打款' }}</span>
                </div>
                <div v-else>
                    --
                </div>
                
            </template>
        </el-table-column>
		<el-table-column label="添加时间"
		                 prop="add_time"
						width="200"
						 align="center">
		</el-table-column>
		
        <!-- <el-table-column label="操作" min-width="130" fixed="right">
          <template slot-scope="scope">
			<el-button type="text" @click="editRow(scope.row)">编辑</el-button>
			<el-button type="text" @click="delRow(scope.row.id)">删除</el-button>
          </template>
        </el-table-column> -->
      </el-table>
	  <div class="page">
	              <el-pagination
	                      background
	                      @size-change="pageChange"
	                      @current-change="handleCurrentChange"
	                      :current-page="page"
	                      :page-size="pageSize"
	                      layout="total, sizes, prev, pager, next, jumper"
	                      :total="page_totle">
	              </el-pagination>
	          </div>
    </el-card>
	
	<!-- 新增角色 -->
	<el-dialog
	  :title="title"
	  :visible.sync="formShow"
	  :close-on-click-modal="false"
	  width="600px">
	  <el-form ref="form" :model="form" label-width="120px">
		  <el-form-item label="状态" prop="age">
			<el-select v-model="form.status" style="width: 200px; margin-right: 10px;" size="small" placeholder="请选择状态">
				<el-option
				v-for="item in statusOptions"
				:key="item.value"
				:label="item.label"
				:value="item.value"
				></el-option>
			</el-select>
		  </el-form-item>
		  <el-form-item label="物流名称" prop="logistics_name">
			<el-input v-model="form.deliveryName" placeholder="请输入物流名称" size="small"></el-input>
		  </el-form-item>
		  <el-form-item label="物流编号" prop="logistics_no">
			<el-input v-model="form.deliveryCode" placeholder="请输入物流编号" size="small"></el-input>
		  </el-form-item>
		  
	  </el-form>
	  <span slot="footer" class="dialog-footer">
	    <el-button size="mini" @click="formShow = false">取 消</el-button>
	    <el-button size="mini" type="primary" @click="confirm">确 定</el-button>
	  </span>
	</el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        title:'新增',
		form:{
			id:null,
			status:0, //状态
			deliveryName:'', //物流名称
			deliveryCode:'', //物流编号
		},
		list:[],
		page:1,
		pageSize:10,
		searchForm:{
			type:'-1', //类型
			status:'-1', //状态
			qr_sn:'', //二维码编号
            user_id:'', //用户id
            s_user_id:"",
		},
		time:[],
        options:[], //奖品列表
		statusOptions:[
			{
				value:'0',
				label:'未领取'
			},
			{
				value:'1',
				label:'已领取未发货'
			},
			{
				value:'2',
				label:'已领取已发货'
			},
			{
				value:'3',
				label:'已完成'
			}
		]
      }
    },
    mounted() {
		this.lodeList()
        this.getPrizeList()
    },
    methods: {
		handleChange(row){
			this.$api.post('/admin/updateCooperationWithdrawApply',{id:row.id,status:row.status}).then(res=>{
				if(res.code==200){
					this.$message({
						message:'操作成功',
						type:'success'
					})
					this.lodeList()
				}
			})
		},
        //获取奖品列表
        getPrizeList(){
				 
		  this.$api.post('/admin/getPrizeList',{searchForm:{}}).then(res=>{
			  let data = res.data
             this.options = data.result
		  })
		},
		
		addBtn(){
			this.form = {
				id:null,
                name:"",
                probability:"", //概率
                desc:'', //备注
			}
			this.title = '新增'
			this.formShow = true
		},

		reset(){
			this.searchForm = {
				type:'-1', //类型
                status:'-1', //状态
                qr_sn:'', //二维码编号
                user_id:'', //用户id
                s_user_id:"",
			}
			this.time = []
			this.mySearch()
		},
		
		editRow(row,type){
			console.log(row)
			this.type = type
			this.title = '编辑'
			for(let i in this.form){
				this.form[i] = row[i]
			}
			this.formShow = true
		
		},
		
		confirm(){
		
		    this.$api.post('/admin/editWinRecord',this.form).then(res=>{
		    	  if(res.code==200){
					  this.formShow = false
		    	  	  this.lodeList()
		    	  }
		    })
		},
		delRow(id){
			this.$confirm('确定删除', '提示', {
					  confirmButtonText: '确定',
					  cancelButtonText: '取消',
					  type: 'warning'
					}).then(() => {
						let params = {
							dd:{id}
						}
					  this.$api.post('/admin/delAwardHistory',params).then(res=>{
					  	  if(res.code==200){
					  	  	this.lodeList()
					  	  }
					  })
			  })
	   },
      lodeList(){
         if(this.time.length>0){
			this.searchForm.start_time = this.time[0]
			this.searchForm.end_time = this.time[1]
		  }
		  let params = {
		          	page:this.page,
		          	pageSize:this.pageSize,
					searchForm:this.searchForm
		    }
		 
		  this.$api.post('/admin/getCooperationWithdrawApply',params).then(res=>{
			  let data = res.data
			  this.page_totle = data.count
			  this.list = data.result
		  })
	  }
      
    }
  }
</script>
